gdk: Provide safe fallback for creating GL contexts
authorEmmanuele Bassi <ebassi@gnome.org>
Mon, 23 May 2016 07:34:39 +0000 (08:34 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 23 May 2016 07:46:53 +0000 (08:46 +0100)
If the backend does not override GdkWindowClass.create_gl_context()
then we should provide a fallback that gives an error, instead of
crashing.

https://bugzilla.gnome.org/show_bug.cgi?id=766782

gdk/gdkwindow.c

index 7625e478cc7ba9a4f810d30b5d1cd724cf9cabe2..d82f8ca285fd7e075c8fd5c44750cadb285d97f0 100644 (file)
@@ -2769,11 +2769,20 @@ gdk_window_get_paint_gl_context (GdkWindow  *window,
 
   if (window->impl_window->gl_paint_context == NULL)
     {
+      GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
+
+      if (impl_class->create_gl_context == NULL)
+        {
+          g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
+                               _("The current backend does not support OpenGL"));
+          return NULL;
+        }
+
       window->impl_window->gl_paint_context =
-        GDK_WINDOW_IMPL_GET_CLASS (window->impl)->create_gl_context (window->impl_window,
-                                                                     TRUE,
-                                                                     NULL,
-                                                                     &internal_error);
+        impl_class->create_gl_context (window->impl_window,
+                                       TRUE,
+                                       NULL,
+                                       &internal_error);
     }
 
   if (internal_error != NULL)